def geneidmapping = new File("geneidmapping.txt")
def homologene = new File("orthology/homologene.data")

def gmap = [:]
geneidmapping.splitEachLine("\t") { line ->
  gmap[line[0]] = line[1]
}

def cmap = [:]
homologene.splitEachLine("\t") { line ->
  def cid = line[0]
  if (cmap[cid] == null) {
    cmap[cid] = new TreeSet()
  }
  def gid = gmap[line[2]]
  if (gid != null) {
    cmap[cid].add(gid)
  }
}

def orthomap = [:]
cmap.keySet().each { cl ->
  def val = cmap[cl]
  val.each { id ->
    if (orthomap[id] == null) {
      orthomap[id] = new TreeSet()
    }
    val.each { id2 ->
      orthomap[id].add(id2)
    }
  }
}
